package model;

import pieces.Piece;

/**
 * This class holds all the neccesary information for recording a move for the purposes of undo and redo.
 * Unfortunately the idea to make a class like this one came so late into the project that the only place it
 * is currently used is in {@link model.ChessBoard} in the undo and redo stacks.
 * @author Sacha Best
 */
public class Move
{
	/**
	 * the {@link model.Location} moved from
	 */
	private final Location from;
	/**
	 * the {@link model.Location} moved to
	 */
	private final Location to;
	/**
	 * the {@link pieces.Piece} move
	 */
	private final Piece fromPiece;
	/**
	 * the {@link pieces.Piece} taken (can be null)
	 */
	private final Piece toPiece;
	/**
	 * This constructor creates a new Move object.
	 * @param from - the {@link model.Location} moved from
	 * @param to - the {@link model.Location} moved to
	 * @param fromPiece - the {@link pieces.Piece} moved
	 * @param toPiece - the {@link pieces.Piece} taken (can be null)
	 */
	public Move(Location from, Location to, Piece fromPiece, Piece toPiece)
	{
		this.from = from;
		this.to = to;
		this.fromPiece = fromPiece;
		this.toPiece = toPiece;
	}
	/**
	 * This method determines whether or not two Move objects are equal
	 * @return true if the two objects are equal, false otherwise
	 */
	public boolean equals(Object other)
	{
		if (!(other instanceof Move))
			return false;
		Move compare = (Move) other;
		boolean locEqual = this.from.equals(compare.getFrom()) && this.to.equals(compare.getTo());
		boolean pieceEqual = this.fromPiece == compare.getFromPiece() && this.toPiece == compare.getToPiece();
		return locEqual && pieceEqual;
	}
	/**
	 * @return the {@link model.Location} moved from
	 */
	public Location getFrom()
	{
		return from;
	}
	/**
	 * @return the {@link model.Location} moved to
	 */
	public Location getTo()
	{
		return to;
	}
	/**
	 * @return the {@link pieces.Piece} moved
	 */
	public Piece getFromPiece()
	{
		return fromPiece;
	}
	/**
	 * @return the {@link pieces.Piece} taken (can be null)
	 */
	public Piece getToPiece()
	{
		return toPiece;
	}
}
